// product下页面混用模块
export default {
  methods: {
    // 获取商品基本属性
    async getAttrList () {
      const result = await this.$api.attrs.reqAttrInfoList(this.category1Id, this.category2Id, this.category3Id)
      if (result.code === 200) {
        this.attrList = result.data
        // console.log(result.data)
        return result.data
      }
    },

    // 获取各级商品id
    getCategoryId ({ categoryId, level }) {
      // 也可以用if...else判断level等级
      // level === 1 ? this.category1Id = categoryId : level === 2 ? this.category2Id = categoryId : this.category3Id = categoryId
      if (level === 1) {
        this.category1Id = categoryId
        // 每次id参数更新都要清空原id
        this.category2Id = ''
        this.category3Id = ''
      } else if (level === 2) {
        this.category2Id = categoryId
        this.category3Id = ''
      } else {
        // 当收到三级菜单的id参数，意味着参数收集完成，开始发送请求获取商品基本属性
        this.category3Id = categoryId
        // console.log('查询商品中...')
        this.getAttrList()
        this.getSpuList()
      }
    }
  }
}
